// pages/videoList/recommend.js
const app = getApp();
const Controller = require('../controllers/controllers.js').controller;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    categorylist:[],
    id:'',
    page:1,
    pageSize:10,
    keyword:'',
    list:[],
    isloading:true
  },

  //跳转
  goPage(e){
    let lessonId = e.currentTarget.dataset["lessonid"]
    let id = e.currentTarget.dataset["id"]
    let type = e.currentTarget.dataset["type"]
    console.log(e.currentTarget.dataset)
    console.log(lessonId)
    if(!lessonId || type==1){
      wx.navigateTo({ url:'/pages/news/detail?id='+id });
      return
    }
    if(type==2){
      wx.navigateTo({ url:'/pages/videoDetails/videoDetails?id='+id });
    }
  },

  //获取列表
  getList(){
    Controller.contentlist({
      keyword:this.data.keyword,
      page:this.data.page,
      pageSize:this.data.pageSize,
      source:1,
      orderBy:1,
    }).then(res=>{
      if(res.code==0){
        let list = this.data.list
        list = list.concat(res.data.baseData.list)
        let lastPage = res.data.baseData.lastPage
        this.setData({
          list,
          lastPage
        })
      }
    })
  },

  //搜索
  submit(){
    this.setData({
      page:1,
      list:[],
      isloading:false
    })
    this.getList()
  },

  //输入
  input(e){
    this.setData({
      keyword: e.detail.value
   });
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getList()
    if(options.parentid){
      app.globalData.parentid=options.parentid
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    if(this.data.lastPage){
      return
    }
    this.setData({
      page:this.data.page+1,
    })
    this.getList()
  },

  onShareAppMessage: function (e) {
    let title = '';
    let imageUrl = '';
    let path=app.getCurrentPageUrlWithArgs()
    let obj = {
      title,
      imageUrl,
      path,
      success: function (res) {},
      fail(err) {}
    }
    return obj
  },
  onShareTimeline: function(res){
    let title = '';
    let imageUrl = '';
    let path=app.getCurrentPageUrlWithArgs()
    let obj = {
      title,
      imageUrl,
      path,
      success: function (res) {},
      fail(err) {}
    }
    return obj
  },
})